package studio.raptor.dispatcher.server.listeners;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.event.ApplicationFailedEvent;
import org.springframework.context.ApplicationListener;

/**
 * 分发器启动失败监听，分发器启动失败是，关闭分发进程
 *
 * @author jack
 * @since 1.0
 */
public class DispatcherFailedListener implements
    ApplicationListener<ApplicationFailedEvent> {

  private static final Logger log = LoggerFactory.getLogger(DispatcherFailedListener.class);

  @Override
  public void onApplicationEvent(ApplicationFailedEvent event) {
    log.error("The dispatcher failed to start......");
    Throwable throwable = event.getException();
    handleThrowable(throwable);
    System.exit(-1);

  }

  private void handleThrowable(Throwable throwable) {
    //处理启动异常
    log.error("dispatcher startup failed", throwable);

  }
}
